<template>
  <div class="login-container">
    <div id="particles-js"></div>
    <div class="login-panel">
      <div class="login-box">
        <div class="title">
          <span class="title-text">临沂商贸物流大数据平台</span>
        </div>
        <div class="login-form">
          <div class="login-title">
            <span class="title-text">系统登录</span>
          </div>
          <el-form :model="ruleForm" status-icon :rules="rules" ref="ruleForm" name="ruleForm" label-width="0px"
            class="demo-ruleForm">
            <div style="margin:0 150px 0 90px;">
              <el-form-item label="" prop="username">
                <el-input v-model.number="ruleForm.username" placeholder="用户名" maxlength="16" autocomplete="off">
                  <!-- <i slot="prefix" class="el-input__icon el-icon-user"></i> -->
                  <span slot="prefix">
                    <img src="../assets/img/login_user.png" alt=""
                      style="width: 40px; height: 36px; position: relative; top: 20px; left: 60px;">
                  </span>
                </el-input>
              </el-form-item>

              <el-form-item label="" prop="password">
                <el-input class="bg2" type="password" v-model="ruleForm.password" placeholder="密码" autocomplete="off"
                  maxlength="16">
                  <!-- <i slot="prefix" class="el-input__icon el-icon-more"></i> -->
                  <span slot="prefix">
                    <img src="../assets/img/login_pwd.png" alt=""
                      style="width: 40px; height: 36px;position: relative; top: 20px; left: 60px;">
                  </span>
                </el-input>
              </el-form-item>
            </div>

            <el-form-item style="margin-top: 60px;">
              <!-- <el-button type="primary" class="btn-block" :loading="loading"
                  @click="submitForm('ruleForm')">登录</el-button> -->
              <div class="btn-block" @click="submitForm('ruleForm')">{{ loginTxt }}</div>
            </el-form-item>
          </el-form>

        </div>
      </div>
    </div>
  </div>
</template>

<script>
import { Message } from 'element-ui';
import { currentPOST2 } from 'api/modules';
import particlesOptions from './login2.js';

export default {
  data() {
    return {
      loading: false,
      loginTxt: '登 录',
      ruleForm: {
        // username: 'dhjs01',
        // password: '1qaz@WSX',
        username: "",
        password: "",
      },
      rules: {
        username: [
          { required: true, message: '请输入用户名', trigger: 'blur' },
        ],
        password: [{ required: true, message: '请输入密码', trigger: 'blur' }],
      },
    };
  },
  mounted() {
    document.onkeydown = () => {
      //!this.clickState是防止用户重复点击回车
      if (window.event.keyCode === 13) this.submitForm('ruleForm');
    };
    particlesJS &&
      particlesJS('particles-js', particlesOptions);
  },
  methods: {
    submitForm(formName) {
      this.$refs[formName].validate((valid) => {
        if (valid) {
          this.loading = true;
          this.loginTxt = '登 录...';
          const params = { ...this.ruleForm, orgId: '' };
          currentPOST2('login', { userData: JSON.stringify(params) }).then(
            (res) => {
              this.loading = false;
              if (res.success) {
                // 清除回车事件
                document.onkeydown = null;
                const token = res.data.token;
                localStorage.setItem('token', token);
                this.$router.push('/launch');
                this.loginTxt = '登 录';
              } else {
                this.loginTxt = '登 录';
                // this.$Message.error(res.msg);
                Message({
                  message: res.msg,
                  type: 'error',
                  offset: 300,
                  // center: true
                });
              }
            }
          );
        } else {
          console.log('error submit!!');
          return false;
        }
      });
    },
  },
};
</script>

<style lang="scss" scoped>
.login-container {
  background-color: #020f1c;
  background-image: url('../assets/img/login_bg.jpg');
  background-repeat: no-repeat;
  background-position: center center;
  background-size: cover;
  width: 100%;
  height: 100vh;
  position: relative;
  overflow: hidden;
}

#particles-js {
  width: 100%;
  height: 100vh;
  pointer-events: none;
}

.login-panel {
  position: absolute;
  left: 50%;
  top: 50%;
  margin-left: -960px;
  margin-top: -540px;
  width: 1920px;
  height: 1080px;
  display: flex;
  justify-content: center;
  align-items: center;
  transform: scale(0.85);
}

// .login-panel:hover {
//   transform: scale(0.86);
//   transition: all 0.8s;
// }

.login-box {
  color: white;
  width: 1100px;
  height: 790px;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  align-items: center;
  // background-color: skyblue;
  // border: 1px solid red;
}

.title {
  position: relative;
  // width: 500px;
  text-align: center;
  background-size: cover;
  color: transparent;
  height: 55px;
  line-height: 46px;

  .title-text {
    font-size: 56px;
    font-weight: 900;
    letter-spacing: 6px;
    width: 100%;
    background: linear-gradient(0deg,
        #0072ff 0%,
        #b5e8ec 48.8525390625%,
        #ffffff 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
  }
}

.login-form {
  width: 1100px;
  height: 640px;
  background-image: url('../assets/img/form_bg.png');
  background-position: center center;
  background-size: contain;
  background-repeat: no-repeat;
  // margin: 60px 90px;
  position: relative;
}

.login-title {
  position: absolute;
  top: 79px;
  left: 300px;
  text-align: center;
  background-size: cover;
  color: transparent;
  width: 482px;
  height: 55px;
  line-height: 46px;

  background: url('../assets/img/login_title_bg.png');
  background-position: center center;
  background-size: contain;
  background-repeat: no-repeat;
  // border: 1px solid red;

  .title-text {
    font-size: 34px;
    line-height: 56px;
    // font-weight: 900;
    letter-spacing: 2px;
    width: 100%;
    color: #FFF;
    font-family: 'Franklin Gothic Medium', 'Arial Narrow', Arial, sans-serif;
    // background: linear-gradient(0deg,
    //     #0072ff 0%,
    //     #539cf5 48.8525390625%,
    //     #dddddd 100%);
    // -webkit-background-clip: text;
    // -webkit-text-fill-color: transparent;
  }
}

.demo-ruleForm {
  padding: 220px 215px;
  padding-top: 200px;

  ::v-deep .el-input__inner {
    // background-color: transparent;
    font-size: 18px;
    margin: 10px 30px;
    border: 1px solid transparent;
    color: #ffffff;
    background-color: rgba(39, 127, 205, 0);
    background-image: url("../assets/img/login-border.png");
    background-repeat: no-repeat;
    background-size: 486px 3px;
    background-position: bottom center;

    text-indent: 60px;
    line-height: 40px;
    // letter-spacing: 3px;
    // text-indent: 1.3em;
    // margin: 5px auto;
    height: 55px;
  }

  ::v-deep .el-form-item__error {
    font-size: 18px;
    padding-left: 120px;
  }
}

.btn-block {
  margin-top: 10px;
  margin-left: 30px;
  width: 613px;
  height: 76px;
  font-size: 28px;
  line-height: 76px;
  // font-weight: bold;
  letter-spacing: 6px;
  text-align: center;
  cursor: pointer;
  background: url('../assets/img/login_btn_bg.png');
  background-position: center center;
  background-size: 613px 76px;
  background-repeat: no-repeat;
}
</style>
